/*
 * @lc app=leetcode.cn id=832 lang=cpp
 *
 * [832] 翻转图像
 */

// @lc code=start
class Solution
{
public:
  vector<vector<int>> flipAndInvertImage(vector<vector<int>>& image)
  {
    // reverse
    for (vector<int>& row : image)
      ReverseRow(row);
    // toggle
    for (vector<int>& row : image)
      for (int& e : row)
        e = !e;
    return image;
  }

  void ReverseRow(vector<int>& row)
  {
    int L = 0, R = row.size() - 1;
    while (L < R) {
      int tmp = row[L];
      row[L++] = row[R];
      row[R--] = tmp;
    }
  }
};
// @lc code=end
